package com.soccerlover9527.jadis.datasturct;

import com.soccerlover9527.jadis.enums.ListInsertPosition;

import java.util.List;

/**
 * <p></p>
 *
 * @author soccerlover9527@gmail.com
 * @since 2023-08-07
 */
public interface JList extends Lengths {
    /**
     * remove and return first element
     *
     * @return first element
     */
    String leftPop();

    /**
     * remove and return last element
     *
     * @return last element
     */
    String rightPop();

    /**
     * get the element in the list by index
     *
     * @param index index
     * @return element
     * @throws IndexOutOfBoundsException if index out of list range
     */
    String indexOf(int index);

    /**
     * insert element to the head of list
     *
     * @param value new value
     * @return new length after insert
     */
    int leftPush(String value);

    /**
     * insert element to the tail of list
     *
     * @param value new value
     * @return new length after insert
     */
    int rightPush(String value);

    /**
     * get the elements in the specified range of the list
     *
     * @param start start index
     * @param end   end index
     * @return list of elements
     */
    List<String> range(int start, int end);

    /**
     * Insert the value before or after the reference value
     *
     * @param position before or after
     * @param pivot    reference value
     * @param value    new value
     * @return list length after insert, -1 if pivot do not exist
     */
    int insert(ListInsertPosition position, String pivot, String value);

    /**
     * remove count N value in list.
     * count > 0: remove elements with value from beginning to end
     * count < 0: remove elements with value from end to head
     * count = 0: remove elements with input value
     *
     * @param count delete count
     * @param value deleted value
     * @return real delete count. return 0 if the
     */
    int remove(int count, String value);

    /**
     * set value to index
     *
     * @param index index
     * @param value new value
     * @throws IndexOutOfBoundsException if index out of range
     */
    void set(int index, String value);

    /**
     * trim a list
     *
     * @param start start index
     * @param end   end index
     */
    void trim(int start, int end);
}
